package com.pc.controller;

import com.pc.enrty.Food;
import com.pc.enrty.Viewed;
import com.pc.service.ViewedService;
import com.pc.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/view/")
public class ViewedController {
    @Autowired
    private ViewedService viewedService;
    @Autowired
    private ResultObject result;
    @RequestMapping("show")
    public ResultObject show(Viewed viewed){
        result.setStatus(400);
        result.setResult(viewedService.findViewed(viewed));
        return result;
    }
    @RequestMapping("add&del")
    public void addAndDeleteViewed(Viewed viewed){
        ArrayList<Food> foods=viewedService.selectByUidAndFid(viewed);
        if (foods.isEmpty()){
            viewedService.addViewed(viewed);
        }
        viewedService.removeViewed(viewed);
    }
}
